import { RuleItem } from 'async-validator/dist-types/index'

export interface Rule extends RuleItem {
    trigger: (string | string[])
}
export interface Rules {
    [field: string]: Rule | Rule[];
}
const rules: Rules = {
    phone: [
        { message: '请输入正确的手机号码', pattern: /^1\d{10}$/, len: 11, type: 'number', trigger: ['blur', 'change'] },
    ],
    psw: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        { message: '至少输入6位密码', min: 6, trigger: ['blur', 'change'] },
    ],
};
export function useRules(keys: string[]): Rules {
    let temp = <Rules>{};
    keys.forEach((key: string) => {
        temp[key] = rules[key];
    });
    return temp;
}